; Draws the menus for upgrading, refueling, exchanging, etc.


; HL is the menu to draw

Draw_Icon_Menu:
 

 

 ld a, (hl)  	;HL points to the menu to draw.  The first byte of the menu
		;is either a 1 or a 0.  0 means draw a 3x3 menu, 1 means
		;draw a soft key menu.  A soft key menu is a 1 x something menu
		;at the bottom of the screen.


 

 or a		;Register A = 0 means that the menu is a 3 x 3 menu

 jr z, Draw_3x3_Menu
 
Draw_Soft_Key_Menu:

 BIT Menu_Cursor_In_Center, (IY + flag)
 jr z, _

 ld de, 39 * 256 + 1
 ld (Money_Amount_Y), de

 xor a
 ld (TagX), a
 ld a, 49
 ld (TagY), a

 RES Menu_Cursor_In_Center, (IY + flag)
_
 inc hl
 ld a, (hl) 	;Register A contains the width
		;of the menu, in pixels 
		;(minus 16)

 
 add a, 16

 rrca \ rrca \ rrca
 ld (Sprite_Width),a
 ld b, 16

 push hl
 pop ix

 ;If the menu is not the menu needed for editing
 ;what ships are in a group, the sprite comes immediately
 ;after the subprogram labels--there are no labels for
 ;text.  We need to determine if the menu is indeed
 ;the ship group menu.

 ld c, a

 ld a, (MenuIdentity)
 cp GroupOfShipsMenu
 jr nz, _

 ld de, 11
 jr ++_
_

 ld a, c
 add a, a
 inc a
 ld d, 0
 ld e, a 
_

 add ix, de
 push hl
 xor a
 ld l, 48


 jr ++_

 

Draw_3x3_Menu:

;Set the location of the menu cursor if the menu just popped up

 BIT Menu_Cursor_In_Center, (IY + flag)	;Does the cursor need to be in the center 
					;when we start up?
 ld de, 55 * 256 + 49
 ld (Money_Amount_Y), de

 jr z, _


 ld a, 16
 ld (TagX), a
 ld a, 33
 ld (TagY), a

 RES Menu_Cursor_In_Center, (IY + flag)

;Draws the menu, not the cursor.

_
 
 ld a, 6
 ld (Sprite_Width),a
 ld b, 48
 xor a
 
 push hl
 pop ix
 
 ld de,37	;In a 3 x 3 menu, there is 18 words of data for text and routines
		;to jump to, and one byte specifying that the menu is indeed a 3x3
		;menu.  37 bytes total to skip to get to the actual sprite data.


 add ix, de	;ix now points to the sprite data

 push hl
 ld l, 16

_
 

 call _Put_Sprite_Overwrite


Draw_Icon_Menu_Cursor:





	;Popping this value and pushing it again fixes an error
		;with the stack pointer

 pop hl
 

 ld a, (MenuIdentity)
 cp GroupOfShipsMenu
 jr z, _


 call Draw_Item_Description	;Displays text that tells what the particular
				;option does

_
 ld a,2				;Displays the cursor
 ld (Sprite_Width),a
 ld b,15
 ld a, (TagY)
 ld l, a
 ld a, (TagX)
 ld ix, Icon_Menu_Cursor



 call _Put_Sprite_XOR


 RET

 
 

Do_Menu_Operation:

 ld hl, (Current_Menu)

 ld a, (hl)
 ld b,0
 
 

 inc hl
 
 or a
 jr z, _

 inc hl

_
 
 add hl, bc
 ld e, (hl)
 inc hl
 ld d, (hl)
 ex de, hl

 jp (hl)

Do_Menu_Operation_Return:
 
 ret








Icon_Menu_Cursor:

	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
